
import {createRouter,createWebHashHistory} from "vue-router";


const router =  createRouter({
    history:createWebHashHistory(),
    routes:[
        {
            path:"/",
            redirect:"/Home"
        },
        {
            path:"/Home",
            component:()=>import("../views/Home.vue")
        },
        {
            path:"/My",
            component:()=>import("../views/My.vue"),
            meta:{
                requiresAuth:true
            }
        },
        {
            path:"/Login",
            component:()=>import("../views/Login.vue"),
            
        }
    ]
});

router.beforeEach((to,from,next)=>{
    if(to.meta.requiresAuth){
        if(!sessionStorage.getItem("username")){
            next({path:"/Login",query:{path:to.path}});
        }else{
            next();
        }
    }else{
        next();
    }
})

export default router;